<?php
/**
 * Jishupu-Laravel-Vue-Admin
 * @Author:技术铺<jishupu@qq.com>
 * @Date: 2021/11/11
 */

namespace App\Http\Resources;

use App\Services\AttachmentService;

/**
 * 信息单页模块资源
 * Class InfoPageResource
 * @package App\Http\Resources
 */
class InfoPageResource extends BaseResource
{
    /**
     * @param \Illuminate\Http\Request $request
     * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
     */
    public function toArray($request)
    {
        return $this->filterFields([
            'info_category_id' => $this->info_category_id,
            'title' => $this->title,
            'cover_image' => AttachmentService::previewList($this->cover_image),
            'keywords' => $this->keywords ? explode(",", $this->keywords) : [],
            'description' => $this->description,
            'content' => $this->content,
//            'hits' => $this->hits,
            'status' => $this->status,
            'created_at' => $this->created_at ? $this->created_at->format('Y-m-d H:i:s') : "",
//            'updated_at' => $this->updated_at ? $this->updated_at->format('Y-m-d H:i:s') : ""
        ]);
    }
}
